home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / GAMMANS / SOCKFS-0.ZIP / S / Modmain
Text File  |  1997-09-07  |  20KB  |  613 lines

  1. ;  Socket.s
  2. ;          : Source code to SocketFS
  3. ;          : BSD sockets as files!
  4. ;
  5. ;  Created :  04-07-97
  6. ;  Author  :  R G Gammans
  7. ;
  8. ;  Modified:  18-08-97
  9.  
  10.  
  11. ;   SocketFS - BSD sockets filing system for RISC-OS.
  12. ;   Copyright (C) 1997 Roger G Gammans
  13. ;
  14. ;   This program is free software; you can redistribute it and/or modify
  15. ;   it under the terms of the GNU General Public License as published by
  16. ;   the Free Software Foundation; either version 2 of the License, or
  17. ;   (at your option) any later version.
  18. ;
  19. ;
  20. ;   This program is distributed in the hope that it will be useful,
  21. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. ;   GNU General Public License for more details.
  24. ;
  25. ;   You should have received a copy of the GNU General Public License
  26. ;   along with this program; if not, write to the Free Software
  27. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. ;
  29. ;   Author: R Gammans <rgammans@compsurg,demon.co.uk>
  30. ;   Snailmail  : 20 Trenches Rd, Crowborough, E Sussex, TN6 1ES UK.
  31. ;
  32.  
  33.  
  34.           GET   AsmLib:s.DebugHdr
  35.  
  36.  ;Debug     SETL  {TRUE}
  37. Debug     SETL  {FALSE}
  38.  
  39.         GET        AsmLib:h.SWINames
  40.                 GET             AsmLib:h.FSControls
  41.                 GET        AsmLib:h.psrFlags
  42.         GET        AsmLib:h.sockConsts
  43.  
  44.          IMPORT      |__RelocCode|
  45.         IMPORT        |_clib_initialisemodule|
  46.         IMPORT        |_clib_finalisemodule|
  47.         IMPORT        |malloc|
  48.         IMPORT        |memcpy|
  49.         IMPORT        |makeSocket|
  50.         IMPORT        |inithandlerlist|
  51.         IMPORT        |_Lib$Reloc$Off$DP|
  52.  
  53.          AREA         |!!Module$Header|, CODE, READONLY
  54.  
  55. Pc        RN        R15
  56. pc        RN        R15
  57. PC        RN        R15
  58.  
  59.  
  60. tempbyte    *        0    ;Use first byte of workspace as dumping ground.
  61.  
  62.  
  63.  
  64. SocketFSMod_BaseAddr
  65.  
  66.         DCD        0
  67.         DCD        Socket_Init    - SocketFSMod_BaseAddr
  68.         DCD         Socket_Die     - SocketFSMod_BaseAddr
  69.         DCD        0            ;Later version will probaly
  70.                             ;handle services
  71.         DCD        Socket_Title   - SocketFSMod_BaseAddr
  72.         DCD        Socket_HelpStr - SocketFSMod_BaseAddr
  73.         DCD        Socket_HC_Table- SocketFSMod_BaseAddr
  74.         DCD        0
  75.         DCD        0
  76.         DCD        0
  77.                 DCD         0
  78.  
  79. Socket_DoSWI
  80. Socket_SWITable
  81.                 DCD         0,0
  82. Socket_Title
  83.         DCB        "SocketFS",0
  84. Socket_HelpStr    DCB        "SocketFS",9,"0.01 (18 Aug 1997) © Roger Gammans. Distribute as per GPL V2",0
  85.         ALIGN
  86. Socket_HC_Table    DCB         "SocketFS",0
  87.          ALIGN
  88.         DCD        socket_selectfs- SocketFSMod_BaseAddr
  89.         DCD        0
  90.         DCD        0
  91.         DCD        socket_selectfs_help- SocketFSMod_BaseAddr
  92.         DCD        0
  93.  
  94.  
  95. socket_selectfs_help
  96.                 DCB         &1b,1,13,13,"This command ",&1b,28,"s",&1b,2,"socket ",&1b,4,0
  97.  
  98. socket_selectfs                                 ;Nicked form PRMs (RO3) P.2-524
  99.                 STMFD       R13!,{R14}
  100.         MOV         R0,#FSControl_selectFS  ;14
  101.         ADR        R1,socket_fsname
  102.                 SWI        XOS_FSControl
  103.         LDMFD        R13!, {PC}
  104.  
  105. Socket_Init
  106.         STMFD        R13!,{R7-R11,r14}
  107.         MOV        R10,R13,LSR #20            ;Which MB boundary is the stack on...
  108.         MOV        R10,R10,LSL #20            ;point R10 directly at booundary...
  109.         LDMIA        R10,{R4,R5}            ;Get relocation for other C SVC modules....
  110.         STMFD        R13!,{R4,R5}            ;hold it safley on top of stack!
  111.         STMFD        R13!,{R12}            ;R12 corruptable under APCS-R....
  112.               ;    BL          __RelocCode            ;Do any relocations and return.
  113.         BL         _clib_initialisemodule        ;We use 'C' functions so...
  114.                 DBSET           DebugOn :OR: UseTracker
  115.               DBF             "\fStarting\n-sp = &%dw\n"
  116.                 MOV         R0,#12                ;12 bytes ws.
  117.                 BL        malloc                ;Allocate it!
  118.         MOVS        R6,R0                ;Set flags from R0
  119.                 BEQ        socket_nomem            ;Can't alloc ret eith error
  120.         LDMFD        R13!,{r12}            ;Get R12 Back..
  121.         LDR        R12,[R12]            ;Get ws frm private word...
  122.         STR        R12,[R6,#4]            ;Store stub's ws ptr.
  123.         DBF        "Doing AF_INIT (sic)  ws@ %4w, %cw\n"
  124.             BL        inithandlerlist            ;Initialise list of known address families
  125.          DBF             "Done AF_INIT ws's @ %4w, %cw\n"
  126.         BL        socket_clibstackunmunge         ;Return stack to SVC std..
  127.         DBF             "Done Stack unmunge...sp = &%dw\n"
  128.                 MOV        R3,R6                ;Pass our ws to FS_control as ws ptr
  129.                 MOV            R0,#FSControl_AddFS
  130.                 ADR           R1,SocketFSMod_BaseAddr
  131.         MOV            R2,# socket_FSinfo - SocketFSMod_BaseAddr
  132.                 DBF        "About to call SWI...\n"
  133.                 SWI            XOS_FSControl                  ;Add FS info to RISC-OS
  134.         DBF        "Done SWI ADDFS\n"
  135.                 LDMFD          R13!,{R7-r11,pc}
  136.  
  137. Socket_Die
  138.                 LDR         R12,[R12]            ;Get pointer to workspace.
  139.                STMFD        R13!,{R14}            ;Save R14 on stack so we can use SWIs
  140.         MOV        R0,#FSControl_removeFS
  141.         ADR        R1,socket_fsname
  142.         SWI         XOS_FSControl                   ;Tell RISC-OS FS is going...
  143.         BL        socket_clibstackmunge
  144.         MOV        R0,R12
  145.                 BL        _clib_finalisemodule
  146.                 BL        socket_clibstackunmunge
  147.                 CMP        PC,#0                ;Clear V flag.
  148.                 LDMFD        R13!,{pc}            ;Done go home.
  149.  
  150. socket_nomem
  151.         LDMFD        R13!,{R12}
  152.         LDMFD        R13!,{R7-R11,R14}
  153.         ADR        R0,socket_nomemmsg
  154.         ORRS        PC,R14,#V_Bit
  155. socket_nomemmsg
  156.         DCD        &001FF01
  157.         DCB        "No memory for filing system",13,0
  158.         ALIGN
  159.  
  160.  
  161.   ;Need to find I bettr way of commenting these bit fields.
  162.   ;socket_info_word EQU        1   << 31+
  163. ;                1   << 30    +              ;Streams are interactive
  164. ;                0   << 29    +        ;FS does support null length names;
  165. ;                1   << 28    +        ;FS should be asked to open Non-existent files
  166. ;                0   << 27       +        ;Use FSEntry Args 255 to flush
  167. ;                1   << 26    +        ;We support FS_File 9
  168. ;                1   << 25    +        ;We support FS_Func 20
  169. ;                0   << 24    +        ;Currently reserved.
  170. ;                0   << 23    +        ;we don't support ImageFS extension
  171. ;                0   << 22    +        ;Do  pass & and % in path
  172. ;                1   << 21    +        ;Need not store dira
  173. ;                1   << 20    +        ;Use Open/Get/Close in pref to File 255
  174. ;                1   << 19    +        ;Use Open/Get/Close in pref to File 0
  175. ;                1   << 18    +        ;Use FS_entry 9 instead of FS_Entry File
  176. ;                0   << 17    +        ;Extra info word not present
  177. ;                0   << 16    +        ;FS writable
  178. ;                &0 << 8    +            ;No defititnve limit to open files.
  179. ;        1   << 31+\
  180.  
  181. socket_info_word      EQU    1   << 31+\
  182.  1   << 30+\
  183.  0   << 29+\
  184.  1   << 28+\
  185.  0   << 27+\
  186.  1   << 26+\
  187.  1   << 25+\
  188.  0   << 24+\
  189.  0   << 23+\
  190.  0   << 22+\
  191.  &F  << 18+\
  192.  0   << 17+\
  193.  0   << 16+\
  194.  0  << 8+\
  195.   &00FF            ;SocketFS Number
  196.  
  197.  
  198. socket_FSinfo
  199.           DCD        socket_fsname     - SocketFSMod_BaseAddr
  200.           DCD        startup_msg     - SocketFSMod_BaseAddr
  201.         DCD          socket_open     - SocketFSMod_BaseAddr
  202.         DCD         socket_read     - SocketFSMod_BaseAddr
  203.           DCD         socket_write     - SocketFSMod_BaseAddr
  204.           DCD         socket_args     - SocketFSMod_BaseAddr
  205.           DCD         socket_close     - SocketFSMod_BaseAddr
  206.           DCD           socket_file     - SocketFSMod_BaseAddr
  207.         DCD         socket_info_word
  208.         DCD         socket_Func     - SocketFSMod_BaseAddr
  209.         DCD         socket_GBPB     - SocketFSMod_BaseAddr
  210.         DCD         0
  211.  
  212. socket_fsname
  213.         DCB        "SocketFS",0
  214.         ALIGN
  215. startup_msg
  216.             DCB         "Internet Filesystem",0
  217.  
  218.         ALIGN
  219.  
  220.  
  221. socket_open
  222.                 STMFD       R13!,{R14}
  223.         DBF        "File open entry called\n"
  224.         MOVS        R0,R6                ;Copy special field over
  225.         DBF        " - spcf = %0s\n" , NE
  226.         DBF        " - no special field\n", EQ
  227.         DBF        " - fname -= %1s\n"        ;reason code...
  228.         LDR        R12,[R12,#4]            ;Get stubs ws.
  229.         BL        socket_clibstackmunge        ;Set stack up for Clib.
  230.                 BL          makeSocket            ;Call C filename processor
  231.                                  ;This give socket in R0
  232.         BL        socket_clibstackunmunge
  233.                                  ; or -1 if no socket opened
  234.              ADD         R1,R0,#1                 ;Make my handle the socket number +1
  235.                                                          ; conveiently 0 now indicates file not found
  236.  
  237.              MOV         R2,#0                          ;Unbuffered...(actually internet mod
  238.                                                      ;will buffer).
  239.              MOV         R3,#0                        ;File extent not used...
  240.              MOV         R4,#0                        ;No buffer space allocated..
  241.              MOV         R0,#&D8000000               ;File Info word
  242.  
  243.              ;File set as readablr,writeable,Stream device and interactive
  244.  
  245.              LDMFD       R13!,{PC}^                   ;Finish...
  246.  
  247.  
  248. socket_read
  249.                 STMFD       R13!,{R14}
  250.         DBF        "File read entry called for socket %1w\n"
  251.                 SUB         R0,R1,#1                       ;Put socket number in R0.
  252.         SUB             R13,R13,#4            ;resevre 1w ws on stack.
  253.                 MOV         R1,R13                    ;Put buffer in R1..
  254.                 MOV         R2,#1                       ;Put buff size in R2
  255.  
  256.                                 ;Ignore file offset as we have streams...
  257.                 SWI         XSocket_Read                ;Call Internet module..
  258.               LDRVC       R0,[R13]                  ;If no error get byte from buff
  259.         ADD        R13,R13,#4            ;Release ws.
  260.                 LDMVCFD     R13!,{PC}^
  261.  
  262.         LDR        R1,[R0]                ;Get Errno
  263.         DBF        "Socket Err %1w\n"
  264.         CMP        R1,#EWOULDBLOCK            ;Is Rx/Tx limits.
  265.         LDMEQFD        R13!,{R14}            ;Get lr early so we can set flags
  266.         MOV        R0,#0                           ;Retrun 0 char - t
  267.         ORREQ        PC,R14,#C_Bit
  268.         ;Now we have to work out what to do in the case of other errs!.
  269.         LDMFD         R13!,{R14}            ;Return with V set!., m
  270.         ORR        PC,R14,#V_Bit            ;Set V flag
  271. socket_write
  272.                 STMFD       R13!,{R1-R2,R14}
  273.         DBF        "File write entry called\n  - R0 %0b\n - R1 %1w\n"
  274.         SUB        R13,R13,#4            ;Resevre 1 w one stack.
  275.                 STR             R0,[R13]                  ;Store byte to send
  276.                 SUB         R0,R1,#1                       ;Put socket number in R0.
  277.                 MOV         R1,R13                   ;Put buffer in R1..
  278.                 MOV         R2,#1                       ;Put buff size in R2
  279.                 SWI         XSocket_Write               ;Call Internet module..
  280.         ADD        R13,R13,#4            ;Release stack ws.
  281.                 LDMFD       R13!,{R1-R2,PC}
  282.  
  283.  
  284. socket_close    STMFD       R13!,{R14}
  285.         DBF        "File close entry called\n"
  286.                 SUB         R0,R1,#1                       ;Put Socket in R0
  287.  
  288.                 ;Ignore other stuff as meaningless.
  289.                 SWI         XSocket_Close               ;Call internet module
  290.                 LDMFD       R13!,{PC}
  291.  
  292. socket_GBPB     ;Optimized multibyte get and put routines.....
  293.                 ;In fact in our case almost simpler than the single byte
  294.                 ;ones
  295.  
  296.                 STMFD       R13!,{R0-R4,R14}
  297.         DBF        "File gpbp entry called op no - %0w\n"
  298.  
  299.                 CMP             R0,#3                       ;Check reason code...
  300.                 BGE         socket_multiget             ;Do get mutliple..
  301.  
  302.                   ;put multiple . move regs to place for socket call
  303.                 SUB         R0,R1,#1
  304.                 MOV         R1,R2
  305.                 MOV         R2,R3
  306.                 SWI         XSocket_Write
  307.         BVS        socket_gbpb_handError
  308.         MOV        R5,R0
  309.         LDMFD        R13!,{R0-R4,R14}
  310.         ADD        R2,R2,R5            ;Compute new buff ptr
  311.         SUB        R3,R3,R5            ;Compute new buff free size
  312.         ADD        R4,R4,R5            ;Compute new file pointer!
  313.         MOVS        PC,R14                ;Return to caller
  314.  
  315. socket_multiget
  316.  
  317.                   ;get multiple . move regs to place for socket call
  318.                 SUB         R0,R1,#1
  319.                 MOV         R1,R2
  320.                 MOV         R2,R3
  321.                 SWI         XSocket_Read
  322.         BVS        socket_gbpb_handError
  323.         MOV        R5,R0
  324.         LDMFD        R13!,{R0-R4,R14}
  325.         ADD        R2,R2,R5            ;Compute new buff ptr
  326.         SUB        R3,R3,R5            ;Compute new buff free size
  327.         ADD        R4,R4,R5            ;Compute new file pointer!
  328.         MOVS        PC,R14                ;Return to caller
  329.  
  330. socket_gbpb_handError
  331.         LDR        R1,[R0]                ;Get Errno
  332.         CMP        R1,#EWOULDBLOCK            ;Is Rx/Tx limits.
  333.         LDMEQFD        R13!,{R0-R4,PC}^        ;Return doing nothing
  334.         ;Fileswitch will work out what to tell client!
  335.  
  336.         ;Now we have to work out what to do in the case of other errs!.
  337.         MOV        R5,R0                ;Save errrblk ptr..
  338.         LDMFD        R13!,{R0-R4,R14}        ;get orignal regs..
  339.         MOV        R0,R5                ;restore errblk ptr
  340.         ORRS        PC,R14,#V_Bit            ;return with V set.
  341.  
  342.  
  343. socket_args    ;Handle wodges of OS_Args codes here!
  344.         STMFD            R13!,{R0-R4,R14}        ;Store Registers!
  345.         DBF         "FS_Entry Args %0w called\n"
  346.         CMP        R0,#10
  347.         ADDLE        PC,PC,R0,LSL #2            ;Use old fashionned
  348.                                 ;Swi dispatch trick
  349.         B         socket_unknownCall
  350.  
  351.         B        socket_returnZero
  352.         LDMFD        R13!,{r0-R4,PC}            ;Ignore ARgs 1
  353.         B        socket_returnZero
  354.         LDMFD        R13!,{R0-R4,PC}            ;Ignore Args 3
  355.         B        socket_allocedsize
  356.         B        socket_EOFcheck            ;Is TCP connection open?
  357.         B        socket_Flush            ;Not called but triv to code!
  358.         B          socket_Extent
  359.         LDMFD        R13!,{R0-R4,PC}            ;Not suported .. unbuffered
  360.         B        socket_returnZeros
  361.         LDMFD        R13!,{R0-R4,PC}            ;If you've implemented an imagefs over socketfs I'd be shocked!
  362.  
  363. socket_allocedsize
  364.         LDMFD        R13!,{R0-R4,R14}
  365.         MOV        R2,#1
  366.         MOV        PC,R14
  367.  
  368. socket_Extent
  369.         LDMFD        R13!,{R0-R4,R14}
  370.         ;What do we need to tell Fileswitch
  371.         MOV               R2,#1
  372.         MOV        PC,R14
  373.  
  374. socket_returnZero
  375.         LDMFD        R13!,{R0-R4,R14}
  376.         MOV        R2,#0                ;Return R2=0
  377.                 MOV         Pc,R14
  378.  
  379. socket_returnZeros
  380.         LDMFD        R13!,{R0-R4,R14}
  381.         MOV        R2,#0                ;Return R2-R3=0.
  382.         MOV        R3,R2
  383.                 MOV         Pc,R14
  384.  
  385. socket_Flush
  386.             LDMFD        R13!,{R0-R4,R14}
  387.         STMFD        R13!,{R1-R4,R14}
  388.          SUB        R0,R1,#1            ;Get File handle
  389.         ADD        R1,R12,#tempbyte
  390.         MOV        R2,#0                ;Send 0 octets
  391.         SWI        XSocket_Send
  392.         LDMFD        R13!,{R1-R4,PC}
  393.  
  394. socket_EOFcheck
  395.             LDMFD        R13!,{R0-R4,R14}
  396.         STMFD        R13!,{R14}
  397.                    SUB        R0,R1,#1            ;Get socket handle
  398.                 ADD        R1,R12,#tempbyte
  399.         MOV        R2,#1                ;Get a byte
  400.         MOV        R3,#(MSG_PEEK + MSG_DONTWAIT)    ;but don't remove it from the queue
  401.                 SWI        XSocket_Recv
  402.                 LDRVS        R1,[R0]                ;If err get ErrNo
  403.         MOVS        R0,R0                ;IF read()==0
  404.         CMPNE        R1,#ECONNRESET            ;  || ==ECONNRESET
  405.         MOV        R2,#0                ; then R2=0
  406.         SUBEQ        R2,R2,#1            ; else R2=-1
  407.         LDMFD        R13!,{PC}^            ;return!
  408.  
  409. socket_unknownCall
  410.         ADR        R0,socket_unknownCallMsg
  411.         ORRS        PC,PC,#V_Bit
  412.         LDMFD        R13,{R0-R4,PC}
  413.  
  414. socket_unknownCallMsg
  415.         DCD        &0001FFEE
  416.         DCB        "Socketfs doesn't support this call",13
  417.         ALIGN
  418.  
  419. socket_Func
  420.         STMFD            R13!,{R0-R4,R14}        ;Store Registers!
  421.         DBF        "FS_Entry Func %0w called\n"
  422.         CMP        R0,#34
  423.         ADDLE        PC,PC,R0,LSL #2            ;Use old fashionned
  424.                                 ;Swi dispatch trick
  425.         B         socket_unknownCall
  426.  
  427.         B        socket_DoNothing        ;FsEntry_Func 0
  428.         B        socket_DoNothing        ;FsEntry_Func 1
  429.         B        socket_DoNothing        ;FsEntry_Func 2
  430.         B        socket_DoNothing        ;FsEntry_Func 3
  431.         B        socket_DoNothing        ;FsEntry_Func 4
  432.         B        socket_DoNothing        ;FsEntry_Func 5
  433.         B        socket_DoNothing        ;FsEntry_Func 6
  434.         B        socket_DoNothing        ;FsEntry_Func 7
  435.         B        socket_rename            ;FsEntry_Func 8
  436.         B        socket_DoNothing        ;FsEntry_Func 9
  437.         B        socket_DoNothing        ;FsEntry_Func 10
  438.         B        socket_readBoot            ;FsEntry_Func 11
  439.         B        socket_readDirName        ;FsEntry_Func 12
  440.         B        socket_readDirName        ;FsEntry_Func 13
  441.         B        socket_readDir            ;FsEntry_Func 14
  442.         B        socket_readDir            ;FsEntry_Func 15
  443.         B        socket_DoNothing        ;FsEntry_Func 16
  444.         B        socket_annouce            ;FsEntry_Func 17
  445.         B        socket_DoNothing        ;FsEntry_Func 18
  446.         B        socket_readDir            ;FsEntry_Func 19
  447.         B        socket_DoNothing        ;FsEntry_Func 20
  448.         B        socket_DoNothing        ;FsEntry_Func 21
  449.         B        socket_DoNothing        ;FsEntry_Func 22
  450.         B        socket_DoNothing        ;FsEntry_Func 23
  451.         B        socket_DoNothing        ;FsEntry_Func 24
  452.         B        socket_readDefects        ;FsEntry_Func 25
  453.         B        socket_DoNothing        ;FsEntry_Func 26
  454.         B        socket_readBoot            ;FsEntry_Func 27
  455.         B        socket_DoNothing        ;FsEntry_Func 28
  456.         B        socket_DoNothing        ;FsEntry_Func 29
  457.         B        socket_readFree            ;FsEntry_Func 30
  458.         B        socket_DoNothing        ;FsEntry_Func 31
  459.         B        socket_DoNothing        ;FsEntry_Func 32
  460.         B        socket_readUsage        ;FsEntry_Func 33
  461.         B        socket_DoNothing        ;FsEntry_Func 34
  462.  
  463.  
  464.     ;Some of the calls that seem to come here should never be called anyway.
  465.         ;(at least assuming the PRMs are correct!)
  466. socket_DoNothing
  467.         LDMFD        R13!,{R0-R4,PC}^        ;Return to fileswitch.
  468.  
  469. socket_rename
  470.     ;Can't Rename sockets so return with error
  471.         LDMFD        R13!,{R0-R4,R14}         ;Tidy stack
  472.         MOV        R0,#1                ;mark rename failed.
  473.         MOVS        pc,r14                ;return
  474.  
  475. socket_DiscBoot
  476.     ;Here we use the 'C' libs memcpy to move our data to Fileswicth
  477.         ;It's overkill for 5 bytes but there an outside chance it
  478.     ;will validate the address for us.
  479.         MOV        R1,R2
  480.         ADR        R0,socket_DiscMsg
  481.         MOV        R2,#socket_DiscMsg - socket_DiscMsgEnd
  482.         BL        memcpy
  483.         LDMFD        R13!,{R0-R4,PC}
  484. socket_DiscMsg
  485.         DCB        3,"tcp",0
  486. socket_DiscMsgEnd
  487.         ALIGN
  488. socket_readDirName
  489.     ;Will need to implement to support RO2
  490.         B        socket_DoNothing
  491.  
  492. socket_readDir
  493.      ;We essentially show an emtpy directry with
  494.     ;these calls so they can all share a routine.
  495.         LDMFD        R13!,{R0-R4,R14}        ;Tidy stack,
  496.         MOV        R3,#0                ;No records read
  497.         STR        R3,[R2]                ;Use 0 to terminate buffer
  498.         MVN        R4,#0                ;End of directory
  499.         MOVS        Pc,R14                ;Return
  500.  
  501. socket_annouce
  502.         SWI        XOS_WriteS
  503.         DCB        "Erk! SocketFS",13,0        ;if socketfs is default at
  504.         ALIGN                        ;boot then you're being clever
  505.                                 ;or have just hung!
  506.         LDMFD        R13!,{R0-R4,PC}
  507.  
  508. socket_readDefects
  509.     ;OK so the internet has them, but not quite in the way
  510.     ;fileswtich means. So we return an empty defect list.
  511.         MOV        R0,#&20000000            ;Load the list terminator
  512.         STR        R0,[R2]                ;Terminate the list's first word
  513.         LDMFD        R13!,{R0-R4,PC}^        ;Preserve regs and return.
  514.  
  515. socket_readBoot
  516.         LDMFD        R13!,{R0-R4,R14}        ;Tidy stack
  517.         MOV        R2,#0                ;Boot opt=0
  518.         MOVS        pc,R14                ;Return.
  519.  
  520. socket_readFree
  521.         LDMFD        R13!,{R0-R4,R14}        ;Tidy stack
  522.         MOV        R0,#0                ;0 free space
  523.         MOV        R1,#0                ;0 cont. free space
  524.         MOV        R2,#0                ;0 disc size
  525.         MOVS        pc,R14                ;Return.
  526.  
  527. socket_readUsage
  528.         LDMFD        R13!,{R0-R4,R14}        ;Tidy stack
  529.         MOV        R2,#2                ;Streams have unique address space
  530.         MOVS        pc,R14                ;Return.
  531.  
  532.  
  533.  
  534. socket_file     DBF        "FS_Entry File %0w called\n"
  535.         TEQ             r0, #255
  536.                 MOVEQ           r0, #10
  537.                 CMP             r0, #(socket_FileTabEnd - socket_FileTab) / 4
  538.                 ADDLE           pc, pc, r0, LSL #2
  539.                 BICS            pc, lr, #V_Bit
  540.  
  541. socket_FileTab  B               socket_Save                   ; Save file
  542.                 BICS            pc, lr, #V_Bit               ; Write catalogue info
  543.                 BICS            pc, lr, #V_Bit               ; Write load address
  544.                 BICS            pc, lr, #V_Bit               ; Write execution address
  545.                 BICS            pc, lr, #V_Bit               ; Write attributes
  546.                 B        socket_readCat                   ; Read catalogue info
  547.                 BICS            pc, lr, #V_Bit               ; Delete object
  548.                 BICS        pc, lr, #V_Bit                 ; Create file
  549.                 BICS            pc, lr, #V_Bit               ; Create directory
  550.                 BICS            pc, lr, #V_Bit               ; Read catalogue info
  551.                 BICS            pc, lr, #V_Bit               ; Load file
  552. socket_FileTabEnd
  553.  
  554.  
  555. socket_Save     STMFD           R13!, {R0-R1, R4, R14}
  556.                 BL              socket_open
  557.                 BEQ             socket_saveErr
  558.         MOV        R6,R5
  559.         MOV        R1,R0
  560.         MOV        R0,#1
  561.         MOV        R2,R4
  562.         SUB        R3,R5,R4
  563. socket_saveloop
  564.                 BGE             socket_saveend
  565.  
  566.                 BL              socket_GBPB
  567.                 BVS             socket_saveErr
  568.         MOVS        R3,R3
  569.                 BEQ             socket_saveloop
  570. socket_saveend  MOV             R0, R1
  571.                 B        socket_close
  572. socket_saveErr
  573.                 LDMFD           sp!, {R0-R1, r4, R14}
  574.         ADR        R0, socket_saveErrMsg
  575.         ORRS        pc, lr, #V_Bit
  576.  
  577.  
  578. socket_saveErrMsg
  579.         DCD         &1006702
  580.         DCB        "An error ocurring while saving",13,0
  581.         ALIGN
  582.  
  583. socket_readCat  ;Currently we don't check wether this is a fully specified address
  584.         ;with sockets in use (eg. an open file - tcp/udp connection)
  585.         MOV        R0,#0                ;File not Found
  586.         BICS        R15,R14,#V_Bit            ;Return no err.
  587.  
  588.  
  589. socket_clibstackmunge
  590.         MOV        R10,R13,LSR #20            ;Which MB boundary is the stack on...
  591.         MOV        R10,R10,LSL #20            ;point R10 directly at booundary...
  592.         LDMIA        R10,{R4,R5}            ;Get relocation for other C SVC modules....
  593.                 STMFD           R13!,{R4,R5}            ;save old reloc modifiers over fn call
  594.         DBF        "Stubs stores relocs @ &%cw\n"
  595.                 LDMIB           R12, {R4, R5}              ;new relocation modifiers
  596.         DBF        "C lib reloc directives are &%4w,&%5w\n"
  597.                 STMIA           R10, {R4, R5}           ;set by module init
  598.                 MOV             fp, #0                  ;halt C backtrace here!
  599.  
  600.                 DCD             |_Lib$Reloc$Off$DP| + &E28AA000  ; This is equivalent of 'ADD r10, r10, #0' + |_Lib$Reloc$Off$DP|
  601.         MOVS        Pc,R14
  602.  
  603. socket_clibstackunmunge
  604.         MOV        R10,R13,LSR #20            ;Which MB boundary is the stack on...
  605.         MOV        R10,R10,LSL #20            ;point R10 directly at booundary...
  606.         LDMIA        R10,{R4,R5}            ;Check so we can match later!
  607.         DBF        "C lib reloc directives are &%4w,&%5w\n"
  608.         LDMFD        R13!,{R4,R5}            ;Get relocation for other C SVC modules....
  609.         STMIA        R10,{R4,R5}            ;put it back where it came from!
  610.         MOVS        Pc,R14
  611.  
  612.         END
  613.